﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using SAC.Helper;
using DAL;
using System.Web;

namespace BLL
{
    public class BLLEeds
    {
        ArrayList list = new ArrayList();
        StringBuilder sb = new StringBuilder();

        //DALData da = new DALData();

        public ArrayList SelectSGLRDAY(string date, string[] point, out string errMsg)
        {
            return DAL.DALEeds.RetSGLRDAY(date, point,out errMsg);
        }

        public bool SaveSGLRDAY(string[] sapoint, string[] val, string date, out string errMsg)
        {
            return DAL.DALEeds.SaveSGLRDAY(sapoint, val, date,out errMsg);
        }

        public ArrayList SelectSGLRBZ(string date, string[] point, string BZ, out string errMsg)
        {
            return DAL.DALEeds.RetSGLRBZ(date, point, BZ, out errMsg);
        }

        public bool SaveSGLRBZ(string[] arrpoint, string[] val, string date, string BZ, out string errMsg)
        {
            return DAL.DALEeds.SaveSGLRBZ(arrpoint, val, date, BZ, out errMsg);
        }

        public string SelectBZ(string TimeBZ, out string errMsg)
        {
            return DAL.DALEeds.RetBZ(TimeBZ, out errMsg);
        }


        public string RetQTJL(string date, string JZ,out string errMsg)
        {
            string[] jl1 = null;
            string[] jl2 = null;
            string[] jl3 = null;
            string[] val = null;
            ArrayList list1 = new ArrayList();
            ArrayList list2 = new ArrayList();

            list1 = DAL.DALEeds.RetSBJL(date, JZ, out errMsg);

            jl1 = (string[])list1[0];
            jl2 = (string[])list1[1];
            jl3 = (string[])list1[2];

            list2 = DAL.DALEeds.RetSBNM(jl3,out errMsg);

            val = (string[])list2[0];

            sb.AppendFormat("<tr style='width: 80%;' bgcolor='#CFE6FC'><td height='18' colspan='4' align='center'  style='width:10' align='center'>#{0}机</td></tr>", JZ);
            sb.Append("<tr style='width: 80%;' bgcolor='#CFE6FC'>");
            sb.Append("<td style='width: 5%;'><div align='center'/>序号</td>");
            sb.Append("<td style='width: 35%;'><div align='center'/>设备名称</td>");
            sb.Append("<td style='width: 30%;'><div align='center'/>启动时间</td>");
            sb.Append("<td style='width: 30%;'><div align='center'/>停止时间</td>");
            sb.Append("</tr>");

            if(jl1!=null || jl2!=null)
            {
                for (int i = 0; i < val.Length; i++)
                {
                    if (val[i] != "")
                    {
                        sb.Append("<tr style='width: 80%;' bgcolor='#FFFFFF'>");
                        sb.AppendFormat("<td style='width: 5%;'><div align='center'/>{0}</td>", (i+1).ToString());
                        sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", val[i]);
                        if (jl1[i] == "")
                        {
                            sb.Append("<td style='width: 35%;'><div align='center'/> - </td>");
                        }
                        else
                        {
                            sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", jl1[i]);
                        }
                        if (jl2[i] == "")
                        {
                            sb.Append("<td style='width: 35%;'><div align='center'/>{0}</td>");
                        }
                        else
                        {
                            sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", jl2[i]);
                        }
                        sb.Append("</tr>");
                    }
                }
            }

            else
            { 
                sb.Append("没有查询到结果..."); 
                return sb.ToString(); 
            }

            return sb.ToString();

        }

        public ArrayList SelectSBNM(string JZ, out string errMsg)
        {
            return DAL.DALEeds.RetSBNMList(JZ,out errMsg);
        }

        public string SelectSBID(string JZ, string SB, out string errMsg)
        {
            return DAL.DALEeds.RetSBID(JZ, SB, out errMsg);
        } 

        public string RetQTJLZB(string dateS, string dateE, string JZ, string SBID, string SB, out string errMsg)
        {
            string[] jl1 = null;
            string[] jl2 = null;
            ArrayList list1 = new ArrayList();

            list1 = DAL.DALEeds.RetSBJLZB(dateS, dateE, JZ, SBID, out errMsg);
            jl1 = (string[])list1[0];
            jl2 = (string[])list1[1];

            sb.AppendFormat("<tr style='width: 80%;' bgcolor='#CFE6FC'><td height='18' colspan='4' align='center'  style='width:10' align='center'>#{0}机</td></tr>", JZ);
            sb.Append("<tr style='width: 80%;' bgcolor='#CFE6FC'>");
            sb.Append("<td style='width: 5%;'><div align='center'/>序号</td>");
            sb.Append("<td style='width: 35%;'><div align='center'/>设备名称</td>");
            sb.Append("<td style='width: 30%;'><div align='center'/>启动时间</td>");
            sb.Append("<td style='width: 30%;'><div align='center'/>停止时间</td>");
            sb.Append("</tr>");

            if (jl1 != null || jl2 != null)
            {
                for (int i = 0; i < jl1.Length; i++)
                {
                    if (jl1[i] == null && jl2[i] == null)
                    {
                        break;
                    }
                    else
                    {
                        sb.Append("<tr style='width: 80%;' bgcolor='#FFFFFF'>");
                        sb.AppendFormat("<td style='width: 5%;'><div align='center'/>{0}</td>", (i + 1).ToString());
                        sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", SB);
                        if (jl1[i] == "")
                        {
                            sb.Append("<td style='width: 35%;'><div align='center'/> - </td>");
                        }
                        else
                        {
                            sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", jl1[i]);
                        }
                        if (jl2[i] == "")
                        {
                            sb.Append("<td style='width: 35%;'><div align='center'/> - </td>");
                        }
                        else
                        {
                            sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", jl2[i]);
                        }
                        sb.Append("</tr>");
                    }
                }
            }

            else
            {
                sb.Append("没有查询到结果...");
                return sb.ToString();
            }

            return sb.ToString();
        }

        /*public string RetTableByLR(string unit)
        {
            list = da.RetArrsByLR(unit);

            string[] zb = (string[])list[0];
            string[] un = (string[])list[1];
            string[] ID1 = (string[])list[2];
            string[] ID2 = (string[])list[3];
            string[] ID3 = (string[])list[4];
            string[] ID4 = (string[])list[5];
            string[] ID0 = (string[])list[6];

            if (list.Count > 0)
            {
                for (int i = 0; i < zb.Length; i++)
                {
                    if (zb[i] != null)
                    {
                        sb.Append("<tr>");

                        sb.AppendFormat("<td align='center' id ='" + zb[i] + "'>{0}</td>", zb[i]);
                        sb.AppendFormat("<td align='center' id ='" + ID1[i] + "'><input type=\"text\" id =\"{0}\" style=\"text-align: center;\" runat=\"server\"/></td>", ID1[i]);
                        sb.AppendFormat("<td align='center'>{0}</td>", un[i]);

                        sb.Append("</tr>");
                    }
                }

                for (int i = 0; i < zb.Length; i++)
                {
                    if (zb[i] != null)
                    {
                        sb.Append("<tr>");

                        sb.AppendFormat("<td align='center' id ='" + zb[i] + "'>{0}</td>", zb[i]);
                        sb.AppendFormat("<td align='center' id ='" + ID2[i] + "'><input type=\"text\" id =\"{0}\" style=\"text-align: center;\" runat=\"server\"/></td>", ID2[i]);
                        sb.AppendFormat("<td align='center'>{0}</td>", un[i]);

                        sb.Append("</tr>");
                    }
                }

                for (int i = 0; i < zb.Length; i++)
                {
                    if (zb[i] != null)
                    {
                        sb.Append("<tr>");

                        sb.AppendFormat("<td align='center' id ='" + zb[i] + "'>{0}</td>", zb[i]);
                        sb.AppendFormat("<td align='center' id ='" + ID3[i] + "'><input type=\"text\" id =\"{0}\" style=\"text-align: center;\" runat=\"server\"/></td>", ID3[i]);
                        sb.AppendFormat("<td align='center'>{0}</td>", un[i]);

                        sb.Append("</tr>");
                    }
                }

                for (int i = 0; i < zb.Length; i++)
                {
                    if (zb[i] != null)
                    {
                        sb.Append("<tr>");

                        sb.AppendFormat("<td align='center' id ='" + zb[i] + "'>{0}</td>", zb[i]);
                        sb.AppendFormat("<td align='center' id ='" + ID4[i] + "'><input type=\"text\" id =\"{0}\" style=\"text-align: center;\" runat=\"server\"/></td>", ID4[i]);
                        sb.AppendFormat("<td align='center'>{0}</td>", un[i]);

                        sb.Append("</tr>");
                    }
                }

                for (int i = 0; i < zb.Length; i++)
                {
                    if (zb[i] != null)
                    {
                        sb.Append("<tr>");

                        sb.AppendFormat("<td align='center' id ='" + zb[i] + "'>{0}</td>", zb[i]);
                        sb.AppendFormat("<td align='center' id ='" + ID0[i] + "'><input type=\"text\" id =\"{0}\" style=\"text-align: center;\" runat=\"server\"/></td>", ID0[i]);
                        sb.AppendFormat("<td align='center'>{0}</td>", un[i]);

                        sb.Append("</tr>");
                    }
                }
            }
            else
            {
                sb.Append("报表内无可维护的记录！");
            }
            return sb.ToString();
        }*/
    }
}
